home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: BatchProcess.rexx 2.25
- ** Copyright © by Patrik M Nydensten
- ** 2/2 1997 Stockholm/Sweden
- **
- ** IE batch script exectuter for Image Engineer 3.4 and
- ** ArexxSupport module 2.1 or higher.
- ** Batch processes selected image files and saves them into a selected
- ** destination directory. Uses IE Batch scripts.
- */
-
- /* Config settings */
-
- CFG_CONFIG_FILE = 'IE:Cfg/BatchProcess.cfg'
-
- CFG_SRC_DIR = 'IE:'
- CFG_DEST_DIR = 'RAM:'
- CFG_MAX_BS = 3
-
- do i = 1 to CFG_MAX_BS
- CFG_BATCH_SCRIPT.i = 'IE:Arexx/Batch/'
- CFG_BU.i = 0
- CFG_SEC_DIR.i = 'IE:'
- CFG_ALP_DIR.i = 'IE:'
- end
-
- CFG_SAVE_FRMT = 0
- CFG_BASE_NAME = 'Output'
- CFG_IE_PRI = '-3'
-
- /* Main program --------------------------- */
-
- /* Variables */
-
- NL='0a'x ; DQ='22'x ; SQ='27'x
-
- options results
- signal on syntax
-
- if ~show(ports,'IMAGEENGINEER') then exit
- address 'IMAGEENGINEER'
-
- /* Read/Setup BP config ------------------- */
-
- call read_config()
-
- /* Get PRIMARY images --------------------- */
-
- call get_multifile('"Select PRIMARY image(s)."','"'CFG_SRC_DIR'"')
- parse var result '"'num_files'"' '"'src_filelist'"'
-
- /* Handle BP settings window -------------- */
-
- do while ok ~= 1
-
- xsrc_filelist = src_filelist ; nil_filelist = '' ; i = 0
- do forever
- parse var xsrc_filelist file ';' xsrc_filelist
- if strip(file) ~= '' then i = i + 1
- else leave
- if i < 6 then nil_filelist = nil_filelist || file || NL
- if i = 6 then nil_filelist = nil_filelist || '[...]' || NL
- prevfile = file
- end
- if i >= 6 then nil_filelist = nil_filelist || prevfile
- else nil_filelist = strip(nil_filelist,'B',NL)
-
- form = 'FORM "BatchProcess 2.2, Image Engineer Batch System" " Go! | File List | Prefs | Exit "',
- ' TEXT,"An IE batch script executer for advanced batch processing.',
- NL'Copyright © 1997 by Patrik M Nydensten"'
-
- do i = 1 to CFG_MAX_BS
- form = form ||' FILE,"Batch script 'i'.","'CFG_BATCH_SCRIPT.i'"',
- ' CYCLE,"Settings:","--|Set for first image only.|Linear mode|Faster mode|Slower mode|Spline mode",'CFG_BU.i
- end
-
- form = form ||' TEXT,"'num_files' images in primary file list:"',
- ' TEXT,"'nil_filelist'"',
- ' DIR,"Destination dir","'CFG_DEST_DIR'"',
- ' STRING,"Output base name","'CFG_BASE_NAME'",25'
-
- form
- if (RC~=0) then do
- 'REQUEST' '"Failed to build GUI !"' '" Reset settings | Abort "'
- if result = 1 then address 'COMMAND' 'delete' CFG_CONFIG_FILE 'QUIET FORCE'
- exit
- end
-
- parse var result ok rest
- if ok = 0 then exit
-
- do i = 1 to CFG_MAX_BS
- parse var rest '"'bscript.i'"' bu.i rest
- end
- parse var rest '"'dst_path'"' '"'dst_filename'"'
-
- if ((right(dst_path,1)~=':')&(right(dst_path,1)~='/')) then dst_path = dst_path||'/'
-
- if ok = 2 then call handle_filelist(src_filelist)
- if ok = 3 then call set_config()
-
- /* Write BP config ------------------------ */
-
- call write_config()
- if ok ~=0 then call read_config()
-
- end /* main window loop */
-
- /* Check batch script --------------------- */
-
- do i = 1 to CFG_MAX_BS /* main MB loop */
- if bu.i = 0 then iterate i
-
- binfo.i = bei('INFO') /* get extra info from batch */
- if word(binfo.i,1) ~= 'OK' then ErrorOut('Error while accessing batch script'NL||bscript.i'!')
-
- /* Get SECONDARY images ----------------- */
-
- if pos('S',binfo.i) ~= 0 then do
- call get_multifile('"Select ('num_files') SECONDARY images for 'get_file(bscript.i)'."','"'CFG_SEC_DIR.i'"')
- parse var result '"'num_sec.i'"' '"'sec_filelist.i'"'
- end
- else do
- num_sec.i = 0 ; sec_filelist.i = '0'
- end
-
- /* Get ALPHA images --------------------- */
-
- if pos('A',binfo.i) ~= 0 then do
- call get_multifile('"Select ('num_files') ALPHA images for 'get_file(bscript.i)'."','"'CFG_ALP_DIR.i'"')
- parse var result '"'num_alp.i'"' '"'alp_filelist.i'"'
- end
- else do
- num_alp.i = 0 ; alp_filelist.i = '0'
- end
-
- /* Get setting(s) for batch script ----- */
-
- if (num_files > 1)&(bu.i>1) then 'REQUEST' '"Select settings for first image.'NL'Batch script:' get_file(bscript.i)'"' '" Continue "'
- bopt_f.i = bei('CONFIG')
- if (bopt_f.i = '<ERROR>') then ErrorOut('Error while retrieving settings from'NL'batch script' bscript.i'!')
-
- if (num_files > 1)&(bu.i>1) then do
- 'REQUEST' '"Select settings for last image.'NL'Batch script:' get_file(bscript.i)'"' '" Continue "'
- bopt_l.i = bei('CONFIG' sq'"'bopt_f.i'"'sq)
- if (bopt_l.i = '<ERROR>') then ErrorOut('Error while retrieving settings from'NL'batch script' bscript.i'!')
- if bu.i > 2 then nil = add_mathlib()
- end
- else bopt_l.i = bopt_f.i
-
- end /* end main MB loop */
-
- call write_config()
-
- /* Start processing ------------------------------------------------ */
-
- 'IE_TO_FRONT'
-
- 'PRIORITY_SET' CFG_IE_PRI
- OLD_IE_PRI = Result
-
- first_batchQ = 1
-
- do i = 1 to CFG_MAX_BS /* MB loop */
- if bu.i = 0 then iterate i
-
- src_filelist_saved = src_filelist
- sec_filelist_saved.i = sec_filelist.i
- alp_filelist_saved.i = alp_filelist.i
-
- do j = 1 to num_files /* Process loop */
-
- parse var src_filelist image_file ';' src_filelist
- if first_batchQ = 0 then image_file = dst_path||dst_filename||'.'||right(j,4,'0')
-
- bei_proc = 'PROCESS' sq'"'image_file'"'sq sq'"'dst_path||dst_filename||'.'||right(j,4,'0')'"'sq sq'"'calc_bopt(j)'"'sq get_info_add()
- Result = bei(bei_proc)
-
- if Result = '<ERROR>' then do
- 'REQUEST' '"Batch script' bscript.i 'returned error while'NL||'processing image' j',' image_file'"' '" Continue | Abort "'
- if (Result = 0) then exit
- end
- end /* end process loop */
-
- first_batchQ = 0
-
- end /* end of MB loop */
-
- 'IE_TO_FRONT'
- 'PRIORITY_SET' OLD_IE_PRI
- 'REQUEST' '" Batch process finished. "' '" Nice! "'
-
- exit
-
- /* Procedures ------------------------------------------------------*/
-
- /* Batch script caller */
-
- BEI:
- parse arg bei_input
-
- if ~exists(bscript.i) then ErrorOut('Failed to load batch script:'NL||bscript.i)
- else interpret 'CALL' '"'bscript.i'"' bei_input
- bei_output = RESULT
-
- address 'IMAGEENGINEER'
- return bei_output
-
- /* Config settings twiner ---------------- */
-
- calc_bopt:
- parse arg cur_filenum
- calc_output = ''
- bopt_fx = bopt_f.i ; bopt_lx = bopt_l.i
- if (bu.i = 1) then calc_output = bopt_fx
- else do forever
- parse var bopt_fx val_fx bopt_fx
- parse var bopt_lx val_lx bopt_lx
- val_fx = strip(val_fx) ; val_lx = strip(val_lx)
- if ((val_fx='OK')|(val_lx='OK')) then leave
- if ((val_fx='')|(val_lx='')) then leave
- if ((left(val_fx,1)='#')|(left(val_lx,1)='#')) then calc_output = calc_output val_fx
- else do /* mode calc */
- select
- when bu.i = 2 then calc_output = calc_output trunc( (val_fx+(val_lx - val_fx)*(cur_filenum-1)/(num_files-1)) )
- when bu.i = 3 then calc_output = calc_output trunc( val_fx+(val_lx-val_fx)*( (exp((-1)+5*(cur_filenum-1)/(num_files-1))-exp(-1)) /exp(4))/0.993262053 )
- when bu.i = 4 then calc_output = calc_output trunc( val_fx+(val_lx-val_fx)*(1-( exp(4-5*(cur_filenum-1)/(num_files-1)) /exp(4)))*1.006783655 )
- when bu.i = 5 then calc_output = calc_output trunc( val_lx-(((cos(3.14159265*(cur_filenum-1)/(num_files-1))+1)/2)*(val_lx-val_fx)) )
- otherwise nop
- end
- end /* end mode calc */
- end
- return strip(calc_output)
-
- /* Output optional extra info if needed --- */
-
- get_info_add:
- info_output = ''
-
- if pos('S',binfo.i)~=0 then do
- do until strip(file)~=''
- parse var sec_filelist.i file ';' sec_filelist.i
- if file = '' then sec_filelist.i = sec_filelist_saved.i
- end
- info_output = sq'"'strip(file,B,'"')'"'sq
- end
-
- if pos('A',binfo.i)~=0 then do
- do until strip(file)~=''
- parse var alp_filelist.i file ';' alp_filelist.i
- if file = '' then alp_filelist.i = alp_filelist_saved.i
- end
- info_output = info_output sq'"'strip(file,B,'"')'"'sq
- end
-
- if pos('F',binfo.i)~=0 then do
- info_output = info_output sq'"'j':'num_files'"'sq
- end
-
- return strip(info_output)
-
- /* Get MultiFile -------------------------- */
-
- get_multifile: PROCEDURE EXPOSE NL
- parse arg '"'gmf_title'"','"'gmf_dir'"'
-
- 'GET_FILES' '"'gmf_title'"' '" OK "' '"'gmf_dir'"'
- gmf_filelist = compress(strip(RESULT),'"')
- if (gmf_filelist=''|RC=5) then exit
-
- /* ReBuild file list */
-
- xgmf_filelist=''; n=0
- do forever
- parse var gmf_filelist file ';' gmf_filelist
- if strip(file)='' then leave
- if (upper(right(file,5))='.LIST') then do
- call read_list_file(file)
- parse var result '"'num_nil'"' '"'nil_filelist'"'
- xgmf_filelist = xgmf_filelist||nil_filelist';'
- n=n+num_nil
- end
- else do
- xgmf_filelist = xgmf_filelist||file';'
- n=n+1
- end
- end
- gmf_filelist=strip(xgmf_filelist,'B',';'); num_gmf=n
-
- /* Ask for cloning of single image */
-
- if num_gmf = 1 then do
- 'FORM "File cloning question" " Accept | Cancel "',
- ' TEXT,"You have only selected one single image. Select the number of clones (copies) of the file',
- NL||'`'gmf_filelist'`, that you would like to use."',
- ' INTEGER,"Number of clones",2,100,10,SLIDER',
- ' INTEGER,"... plus",0,9899,0,SLIDER'
-
- parse var result ok gmf_clones gmf_clonesb
- if ok = 0 then exit
- gmf_clones = gmf_clones + gmf_clonesb
-
- xgmf_filelist = ''
- do n = 1 to gmf_clones
- xgmf_filelist = xgmf_filelist || gmf_filelist || ';'
- end
- gmf_filelist = strip(xgmf_filelist,'B',';')
- num_gmf = gmf_clones
-
- end /* cloning */
-
- /* Ask for index range selection */
-
- if num_gmf = 2 then do
- parse var gmf_filelist file_1 ';' file_2 ';'
- call check_index_range(file_1,file_2)
- parse var result '"'num_gmf'"' '"'gmf_filelist'"'
- end
-
- if num_gmf < 2 then ErrorOut('Bad number of selected files!')
- return '"'num_gmf'"' '"'gmf_filelist'"'
-
- check_index_range: PROCEDURE EXPOSE NL
- parse arg file_1, file_2
-
- base = get_base(file_1)'.'
- base_2 = get_base(file_2)'.'
- ix_1 = get_ext(file_1) ; zlen = length(ix_1)
- ix_2 = get_ext(file_2)
- if (base=base_2)&(datatype(ix_1,'N'))&(datatype(ix_2,'N'))&(ix_2-ix_1>1) then do
- 'REQUEST' '"You have selected two images, both with the same base name'NL||,
- 'and both with an index number. Would you like to include all'NL||,
- 'images within the index range? ('ix_2-ix_1+1' images)'NL||NL||,
- '('base',' ix_1 'and' ix_2')"' '"Yes, index range|No, two images"'
- if (Result = 1) then do
- range_list = '' ; index_fix = 0
- do n = strip(ix_1,L,'0') to strip(ix_2,L,'0')
- if ~exists(base || right(n,zlen,'0')) then do
- if skip_all ~= 1 then do
- 'REQUEST' '"Could not locate file:'NL ||base||right(n,zlen,'0')'"' '"Skip image|Skip all|Abort action"'
- if Result ~= 0 then index_fix = index_fix + 1
- if Result = 2 then skip_all = 1
- if Result = 0 then exit
- end
- else index_fix = index_fix + 1
- end
- else range_list = range_list || base || right(n,zlen,'0')||';'
- end
- num_range = ix_2 - ix_1 + 1 - index_fix
- if (index_fix>0) then 'REQUEST' '"Skipped' index_fix 'images.' num_range 'images found."' '"Continue"'
- if num_range < 2 then exit
- end /* Do index range? */
- else do; range_list = file_1';'file_2 ; num_range=2 ; end
- end /* Index files? */
- return '"'num_range'"' '"'range_list'"'
-
- read_list_file: PROCEDURE EXPOSE NL
- parse arg rlf_file
- num_rlf = 0; rlf_filelist = ''
- if open(rlf_file,rlf_file,'R') then do
- do forever
- read = strip(readln(rlf_file),B,'"')
- if strip(read) = '' then leave
- if ~exists(read) then do
- 'REQUEST' '"File list error on line' num_rlf+1'. Could not load'NL'file `'read'`.'NL||NL'('rlf_file')"' '" Continue "'
- iterate
- end
- if (upper(right(read,5))='.LIST') then do
- call read_list_file(read)
- parse var result '"'num_nil'"' '"'nil_filelist'"'
- rlf_filelist = rlf_filelist||nil_filelist';'
- num_rlf=num_rlf+num_nil
- end
- else do
- num_rlf = num_rlf+1; rlf_filelist = rlf_filelist||read||';'
- end
- end
- 'REQUEST' '"The' rlf_file||NL'file list resulted in' num_rlf 'loaded files."' '" Continue "'
- call close(rlf_file)
- if num_rlf = 0 then 'REQUEST' '"File list `'rlf_file'` is empty."' '" OK "'
- end
- else 'REQUEST' '"Failed to access file list `'rlf_file'`.'NL'Looped linking?"' '" OK "'
- if num_rlf = 2 then do
- parse var rlf_filelist file_1 ';' file_2 ';'
- call check_index_range(file_1,file_2)
- parse var result '"'num_rlf'"' '"'rlf_filelist'"'
- end
- return '"'num_rlf'"' '"'strip(rlf_filelist,'B',';')'"'
-
- /* Config read/write/set ------------------ */
-
- read_config:
- if exists(CFG_CONFIG_FILE) then do
- if open('cfg',CFG_CONFIG_FILE,'R') then do
- if readln('cfg')='BPCFGV:1' then do
- CFG_SRC_DIR = readln('cfg')
- CFG_DEST_DIR = readln('cfg')
- CFG_MAX_BS = readln('cfg')
- do i = 1 to CFG_MAX_BS
- CFG_BATCH_SCRIPT.i = readln('cfg')
- CFG_BU.i = readln('cfg')
- CFG_SEC_DIR.i = readln('cfg')
- CFG_ALP_DIR.i = readln('cfg')
- sec_filelist.i = ''
- alp_filelist.i = ''
- end
- CFG_SAVE_FRMT = readln('cfg')
- CFG_BASE_NAME = readln('cfg')
- CFG_IE_PRI = readln('cfg')
- end
- call close('cfg')
- end
- end
- sf = CFG_SAVE_FRMT; select
- when sf = 1 then sf = 'ILBM uncompressed'
- when sf = 2 then sf = 'DEEP'
- when sf = 3 then sf = 'YUVN (411)'
- otherwise do; sf = 'ILBM CmpByteRun1'; CFG_SAVE_FRMT=0; end
- end; call setclip('cfg_save_frmt',sf)
- return 'OK'
-
- write_config:
- if open('cfg',CFG_CONFIG_FILE,'W') then do
- call writeln('cfg','BPCFGV:1')
- parse var src_filelist nil ';' xnil
- call writeln('cfg',get_path(nil))
- call writeln('cfg',dst_path)
- call writeln('cfg',strip(CFG_MAX_BS))
- do i = 1 to CFG_MAX_BS
- if symbol('bscript.'i)='VAR' then call writeln('cfg',bscript.i)
- else call writeln('cfg','IE:ARexx/Batch/')
- if symbol('bu.'i)='VAR' then call writeln('cfg',bu.i)
- else call writeln('cfg','0')
- if sec_filelist.i = '' then call writeln('cfg',CFG_SEC_DIR.i)
- else do
- parse var sec_filelist.i nil ';' xnil
- call writeln('cfg',get_path(nil))
- end
- if alp_filelist.i = '' then call writeln('cfg',CFG_ALP_DIR.i)
- else do
- parse var alp_filelist.i nil ';' xnil
- call writeln('cfg',get_path(nil))
- end
- end
- call writeln('cfg',strip(CFG_SAVE_FRMT))
- call writeln('cfg',strip(dst_filename))
- call writeln('cfg',strip(CFG_IE_PRI))
- call close('cfg')
- end
- return 'OK'
-
- set_config: PROCEDURE EXPOSE NL CFG_SAVE_FRMT CFG_MAX_BS CFG_IE_PRI
- 'FORM "BatchProcess Prefs" " Save | Cancel "',
- ' TEXT,"This is the save file format that is suggested by this executer to the batch scripts.',
- NL'Not all scripts are aware of this option and not all can actually use it."',
- ' CYCLE,"Save format:","ILBM24 CmpByteRun1|ILBM24 uncompressed|DEEP|YUVN (411)",'CFG_SAVE_FRMT,
- ' TEXT,"This is the number of batch script gadgets that are available in the main window."',
- ' INTEGER,"Number of batch scripts",1,30,'CFG_MAX_BS',SLIDER',
- ' TEXT,"This is the task priority that IE will have while processing images."',
- ' INTEGER,"Priority",-10,5,'CFG_IE_PRI',SLIDER'
-
- parse var result ok rest
- if ok = 1 then parse var rest CFG_SAVE_FRMT CFG_MAX_BS CFG_IE_PRI
- return 'OK'
-
- /* File list proc. ------------------------ */
-
- handle_filelist: PROCEDURE EXPOSE NL src_filelist num_files dst_path CFG_SRC_DIR
- parse arg hfl_filelist
- tpfl = 'the primary file list'
- 'FORM "BatchProcess File List Handler" " Done | Load | Save | Load dir | Reverse "',
- 'TEXT,"Load - selects new files for' tpfl'.'NL||,
- 'Save - saves' tpfl 'to disk.'NL||,
- 'Load dir - loads all files in a directory to' tpfl'.'NL||,
- 'Reverse - changes the order in' tpfl'."'
-
- parse var result hfl_ok '"'save_dir'"'
- if hfl_ok = 1 then return 'OK'
- if hfl_ok = 2 then do
- call get_multifile('"Select PRIMARY image(s)."','"'CFG_SRC_DIR'"')
- parse var result '"'num_files'"' '"'src_filelist'"'
- end
- if hfl_ok = 3 then call write_filelist(hfl_filelist)
- if hfl_ok = 4 then do
- 'GET_DIR' '"Select a directory to load."' '" Load dir "'
- if (RC=5) then exit
- parse var result loadd
- address 'COMMAND' 'list >t:BP.list' '"'loadd'"' 'LFORMAT "%p%n" FILES'
- address 'COMMAND' 'sort FROM t:BP.list TO t:BP.list'
- call read_list_file('t:BP.list')
- parse var result '"'num_files'"' '"'src_filelist'"'
- end
- if hfl_ok = 0 then do
- hfl_filelist=''
- do forever
- parse var src_filelist file ';' src_filelist
- if strip(file)='' then leave
- hfl_filelist = file||';'hfl_filelist
- end
- src_filelist=strip(hfl_filelist,'B',';')
- end
- return 'OK'
-
- write_filelist: PROCEDURE EXPOSE NL dst_path
- parse arg wfl_filelist
- 'GET_FILE' '"Enter a file list name to save."' '" Save "' '"'dst_path'"'
- if (RC=5) then exit
- parse var result wfl_file
- if (upper(right(wfl_file,5))~='.LIST') then wfl_file = wfl_file||'.list'
- n = 0
- if open('fl',wfl_file,'W') then do forever
- parse var wfl_filelist file ';' wfl_filelist
- if strip(file)='' then leave
- call writeln('fl',file); n=n+1
- end
- else ErrorOut('Failed to open output file list file!')
- call close('fl');
- 'REQUEST' '"Wrote' n 'file names to file list'NL'`'wfl_file'`."' '" Continue "'
- return 'OK'
-
- /* Additional procedures ------------------ */
-
- get_path: PROCEDURE
- parse arg get_path_in
- if lastpos('/',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos('/',get_path_in))
- else if lastpos(':',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos(':',get_path_in))
- else get_path_back = ''
- return get_path_back
-
- get_file: PROCEDURE
- parse arg get_file_in
- if lastpos('/',get_file_in) ~= 0 then get_file_back = substr(get_file_in,1+lastpos('/',get_file_in))
- else if lastpos(':',get_file_in) ~= 0 then get_file_back = substr(get_file_in,1+lastpos(':',get_file_in))
- else get_file_back = get_file_in
- return get_file_back
-
- get_ext: PROCEDURE
- parse arg get_ext_in
- if lastpos('.',get_ext_in) ~= 0 then get_ext_back = substr(get_ext_in,1+lastpos('.',get_ext_in))
- else get_ext_back = ''
- return get_ext_back
-
- get_base: PROCEDURE
- parse arg get_base_in
- if lastpos('.',get_base_in) ~= 0 then get_base_back = substr(get_base_in,1,lastpos('.',get_base_in)-1)
- else get_base_back = get_base_in
- return get_base_back
-
- add_mathlib: PROCEDURE
- if ~show(L,'rexxmathlib.library') then do
- if exists('LIBS:rexxmathlib.library') then do
- if ~addlib('rexxmathlib.library',0,-30,0) then ,
- 'REQUEST' '"Failed to load libs:rexxmathlib.library!"' '" OK "'
- end /* lib found on disk */
- else 'REQUEST' '"Failed to find libs:rexxmathlib.library!"' '" OK "'
- end /* lib exists in mem */
- return 'OK'
-
- ErrorOut:
- parse arg string
- 'REQUEST' '"'string'"' '" Abort "'
- exit
- end
-
- SYNTAX:
- SYNTAX_RC = RC
- 'IE_TO_FRONT'
- 'PRIORITY_SET' '0'
- 'REQUEST' '"Internal error on line' SIGL||NL||,
- 'Error' SYNTAX_RC':' errortext(SYNTAX_RC)'"' '" Abort "'
- EXIT
- RETURN 0
-